﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess.Menu;
using System.Data;
namespace Bussiness.Menu
{
    public class MenuBLL
    {
        private MenuDAL dal;
        public MenuBLL()
        {
            dal = new MenuDAL();
        }
        public List<FOModels.Menu.Menu> getmenubytypeid(int menutypeid,int langid)
        {
            List<FOModels.Menu.Menu> list = new List<FOModels.Menu.Menu>();
            DataTable tb = dal.getMenuType(menutypeid,langid);
            if(tb!=null)
            {
                FOModels.Menu.Menu menu;
                foreach (DataRow r in tb.Rows)
                {
                    menu = new FOModels.Menu.Menu();
                    menu.MenuID = int.Parse(r[0].ToString());
                    menu.Name = r[9].ToString();
                    menu.Links = r[3].ToString();
                    menu.Target = r[4].ToString();
                    menu.Enable = bool.Parse(r[5].ToString());
                    list.Add(menu);
                }
            }
            return list;
        }
        public List<FOModels.Menu.Menu> getmenubyparentid(int parentid,int langid)
        {
            List<FOModels.Menu.Menu> list = new List<FOModels.Menu.Menu>();
            DataTable tb = dal.getsubmenus(parentid,langid);
            if (tb != null)
            {
                FOModels.Menu.Menu menu;
                foreach (DataRow r in tb.Rows)
                {
                    menu = new FOModels.Menu.Menu();
                    menu.MenuID = int.Parse(r[0].ToString());
                    menu.Name = r[9].ToString();
                    menu.Links = r[3].ToString();
                    menu.Target = r[4].ToString();
                    menu.Enable = bool.Parse(r[5].ToString());
                    list.Add(menu);
                }
            }
            return list;
        }
        public List<FOModels.Menu.MainMenu> getmainmenu(int langid)
        {
            List<FOModels.Menu.MainMenu> list = new List<FOModels.Menu.MainMenu>();
            DataTable tb = dal.getmainmenu(langid);
            if (tb != null)
            {
                FOModels.Menu.MainMenu menu;
                foreach (DataRow r in tb.Rows)
                {
                    menu = new FOModels.Menu.MainMenu();
                    menu.MenuID = int.Parse(r[0].ToString());
                    menu.Links = r[2].ToString();
                    menu.Name = r[18].ToString();
                    menu.Target = r[3].ToString();
                    menu.Enable = bool.Parse(r[4].ToString());
                    menu.Rel = r[6].ToString();
                    menu.ID = r[7].ToString();
                    menu.Class = r[8].ToString();
                    menu.ULClass = r[9].ToString();
                    menu.LiClass = r[10].ToString();
                    menu.Span = bool.Parse(r[11].ToString());
                    menu.Icon = r[12].ToString();
                    menu.Border = bool.Parse(r[13].ToString());
                    menu.Border_Bot = bool.Parse(r[14].ToString());
                    list.Add(menu);
                }
            }
            return list;
        }
        public List<FOModels.Menu.MainMenu> getsubmainmenus(int parentid,int langid)
        {
            List<FOModels.Menu.MainMenu> list = new List<FOModels.Menu.MainMenu>();
            DataTable tb = dal.getsubmainmenus(parentid,langid);
            if (tb != null)
            {
                FOModels.Menu.MainMenu menu;
                foreach (DataRow r in tb.Rows)
                {
                    menu = new FOModels.Menu.MainMenu();
                    menu.MenuID = int.Parse(r[0].ToString());
                    menu.Links = r[2].ToString();
                    menu.Name = r[18].ToString();
                    menu.Target = r[3].ToString();
                    menu.Enable = bool.Parse(r[4].ToString());
                    menu.Rel = r[6].ToString();
                    menu.ID = r[7].ToString();
                    menu.Class = r[8].ToString();
                    menu.ULClass = r[9].ToString();
                    menu.LiClass = r[10].ToString();
                    menu.Span = bool.Parse(r[11].ToString());
                    menu.Icon = r[12].ToString();
                    menu.Border = bool.Parse(r[13].ToString());
                    menu.Border_Bot = bool.Parse(r[14].ToString());
                    list.Add(menu);
                }
            }
            return list;
        }
    }
}
